/**
 * LocationAPITools library, version 1.0.2
 * 
 * WWW: http://code.google.com/p/locationapitools
 *   
 * Summary:
 *   A collection of classes that simplify the development of location-aware mobile
 *   applications using the JSR-179 Location API on the J2ME (CLDC/MIDP) platform,
 *   e.g. on GPS-equipped smartphones.
 * 
 * Author:
 *   Matthias Stevens (Sony CSL Paris / Vrije Universiteit Brussel)
 *   Contact: matthias.stevens@gmail.com
 *  
 * Description:
 *   The primary use case is a location tracker that stores tracks in KML
 *   (cfr. Google Earth/Maps), CSV or plain text format.
 * 
 *   Package "com.sony.csl.j2me.locationapitools.demo" contains a MIDlet class that
 *   demonstrates how LocationAPITools can be used to create simple GPS tracker
 *   application that produces KML files. For examples of more advanced uses of this
 *   library refer to the NoiseTube project (see below, look for "NoiseTube MobileNoiseTagger").
 * 
 *   The code is known to be working on the following Symbian OS-based platforms:
 *     * S60 3rd Edition Feature Pack 1 (Symbian OS 9.2), e.g.: Nokia N95 and Nokia N95 8GB smartphones
 *     * S60 3rd Edition Feature Pack 2 (Symbian OS 9.3) 
 *   Although this is untested, the code should also work on other (non-Symbian/S60)
 *   J2ME CLDC/MIDP platforms/devices, as long as the JSR-179 Location API is supported
 *   on the platform/device in question.
 * 
 *   This library was developed within the scope of the NoiseTube project at
 *   Sony Computer Science Laboratory (CSL) Paris, for more information please refer to:
 *     * http://noisetube.net
 *     * http://code.google.com/p/noisetube
 *     * http://www.csl.sony.fr 
 *    
 * License: 
 *   Copyright 2008-2009 Sony CSL Paris
 *   Licensed under the Apache License, Version 2.0 (the "License"); you may not use
 *   this file except in compliance with the License. You may obtain a copy of the
 *   License at http://www.apache.org/licenses/LICENSE-2.0.
 *   Unless required by applicable law or agreed to in writing, software distributed
 *   under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
 *   CONDITIONS OF ANY KIND, either express or implied. See the License for the
 *   specific language governing permissions and limitations under the License.
 */

package com.sony.csl.j2me.locationapitools.demo;

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Item;
import javax.microedition.lcdui.StringItem;



/**
 * @author mstevens
 *
 */
public class LocationInfoForm extends Form implements CommandListener
{

	private DemoMIDlet midlet;
	
	//State:
	private String strNumberOfLocations = "0";
	private String strCurrentLocation = "Unknown (waiting for location to be captured)";
	
	//Commands:
	protected Command cmdBack;
    
	//Rest of GUI:
	protected StringItem stritNumberOfLocations;
	protected StringItem stritCurrentLocation;
    
	
	public LocationInfoForm(DemoMIDlet midlet)
    {
		super("Location info");
		this.midlet = midlet;

		//Instantiate form elements:
		cmdBack = new Command("Back", Command.BACK, 1);
		stritNumberOfLocations = new StringItem("Number of captured locations:", strNumberOfLocations);
		stritNumberOfLocations.setFont(Font.getFont(Font.FACE_PROPORTIONAL, Font.STYLE_PLAIN, Font.SIZE_SMALL));
		stritCurrentLocation = new StringItem("Current location:", strCurrentLocation);		
		stritCurrentLocation.setLayout(Item.LAYOUT_EXPAND | Item.LAYOUT_VEXPAND);
		stritCurrentLocation.setFont(Font.getFont(Font.FACE_PROPORTIONAL, Font.STYLE_PLAIN, Font.SIZE_SMALL));
		//Add form elements to the form:	
		this.addCommand(cmdBack);
		this.append(stritNumberOfLocations);
		this.append(stritCurrentLocation);
		
		this.setCommandListener(this);
	}
	
	public void setStrNumberOfLocations(String strNumberOfLocations)
	{
		this.strNumberOfLocations = strNumberOfLocations;
		stritNumberOfLocations.setText(strNumberOfLocations);
	}

	public void setStrCurrentLocation(String strCurrentLocation)
	{
		this.strCurrentLocation = strCurrentLocation;
		stritCurrentLocation.setText(strCurrentLocation);
	}

	public void commandAction(Command cmd, Displayable disp)
	{
		if(cmd == cmdBack)
		{
			DemoMIDlet.getDisplay().setCurrent(midlet.getMainForm());
		}
	}
	
}
